<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加产品</title>
    <#assign path="${springMacroRequestContext.getContextPath()}" >
    <link rel="stylesheet" href="${path}/static/bootstrap-3.4.1/css/bootstrap.css" type="text/css"/>
    <link rel="stylesheet" href="${path}/static/bootstrap-3.4.1/css/bootstrap-theme.css" type="text/css"/>
    <script src="${path}/static/bootstrap-3.4.1/js/jquery.min.js"></script>
    <script src="${path}/static/bootstrap-3.4.1/js/bootstrap.js"></script>
</head>
</head>
<body>
<div class="container">
    <p></p>

    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">添加导航</h3>
        </div>
        <div class="panel-body">
            <form id="prodForm">
                <input type="hidden" class="form-control" name="prodType" value="${prodType.id}">
                <div class="form-group">
                    <label for="groupId">*分组</label>
                    <select class="form-control" id="groupId" name="groupId">
                        <option value="-1">其他</option>
                        <#if prodGroupList??>
                        <#list prodGroupList as group>
                        <option value="${group.id}">${group.groupName}</option>
                        </#list>
                        </#if>
                    </select>
               </div>
                <div class="form-group">
                    <label for="prodName">*导航名称</label>
                    <input type="text" class="form-control" id="prodName" name="prodName" placeholder="产品名称">
                </div>
                <div class="form-group">
                    <label for="welcomeFile">*导航页面</label>
                    <input type="text" class="form-control" id="welcomeFile" name="welcomeFile" placeholder="欢迎页面" value="http://">
                </div>
                <div class="alert bg-danger" id="warnTips" style="display: none;"></div>
                <div class="alert bg-info" id="doingTips" style="display: none;">提交中</div>
                <div class="alert bg-primary" id="successTips" style="display: none;">创建成功</div>
                <button type="button" class="btn btn-primary" id="sub1">提交</button>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $("#sub1").click(function () {
        if ("" == $("#prodName").val()) {
            $(".alert").hide();
            $("#warnTips").html("请输入产品名称").show();
            return;
        } else if ("" == $("#welcomeFile").val()) {
            $(".alert").hide();
            $("#warnTips").html("欢迎页面").show();
            return;
        }
        $.ajax({
            url: '${path}/create',
            type: 'post',
            timeout: 30000,
            data: $("#prodForm").serialize(),
            beforeSend: function () {
                $(".alert").hide();
                $("#doingTips").show();
            },
            success: function (result) {
                if (0 == result.error) {
                    $("#prodForm").find("input").each(function () {
                        if ($(this).attr("name") != undefined && $(this).attr("name") !== "") {
                            $(this).val("");
                        }
                    })
                    $(".alert").hide();
                    $("#successTips").show();
                    setTimeout(function (){
                        window.location.href="${path}/list";
                    },1000);
                } else {
                    $(".alert").hide();
                    $("#warnTips").html(result.msg).show();
                }

            }
        });
    });
</script>
</body>
</html>